import { _decorator } from 'cc';
import Singleton from '../util/Singleton';
import engine from '../Engine';
import { LocalStorage as GameLocalStorage } from './GF_Constant';
const { ccclass, property } = _decorator;

@ccclass('GF_DynamicData')
export class GF_DynamicData extends Singleton<GF_DynamicData>() {

    //音乐开关
    private _musicValue: boolean = null;

    public get music() {
        if (this._musicValue == null) {
            this._musicValue = engine.localStorage.getItem(GameLocalStorage.GameMusic);
            if (this._musicValue == null) {
                this._musicValue = true;
                this.music = this._musicValue;
            }
        }
        return this._musicValue;
    }
    public set music(value: boolean) {
        this._musicValue = value;
        engine.localStorage.setItem(GameLocalStorage.GameMusic, value);
    }


    //音效开关
    private _soundValue: boolean = null

    public get sound() {
        if (this._soundValue == null) {
            this._soundValue = engine.localStorage.getItem(GameLocalStorage.GameSound);
            if (this._soundValue == null) {
                this._soundValue = true;
                this.sound = this._soundValue;
            }
        }

        return this._soundValue;
    }
    public set sound(value: boolean) {
        this._soundValue = value;
        engine.localStorage.setItem(GameLocalStorage.GameSound, value);
    }


    //震动开关
    private _vibrateValue: boolean = null

    public get vibrate() {
        if (this._vibrateValue == null) {
            this._vibrateValue = engine.localStorage.getItem(GameLocalStorage.GameVibrate);
            if (this._vibrateValue == null) {
                this._vibrateValue = true;
                this.vibrate = this._vibrateValue;
            }
        }
        return this._vibrateValue;
    }
    public set vibrate(value: boolean) {
        this._vibrateValue = value;
        engine.localStorage.setItem(GameLocalStorage.GameVibrate, value);
    }



}


